import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [{
      path: '/redirect/:path(.*)',
      component: () =>
        import('@/views/redirect/index')
    }]
  },
  {
    path: '/login',
    component: () =>
      import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () =>
      import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () =>
      import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () =>
      import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [{
      path: 'home',
      component: () =>
        import('@/views/home/index'),
      name: 'home',
      meta: {
        title: '首页',
        icon: 'el-icon-s-home',
        affix: true
      }
    }]
  },
  {
    path: '/weather',
    component: Layout,
    redirect: '/weather',
    children: [{
      path: 'weather',
      component: () =>
        import('@/views/weather/index'),
      name: 'weather',
      meta: {
        title: '天气查询',
        icon: 'el-icon-sunny',
        noCache: true
      }
    }]
  },
  {
    path: '/joke',
    component: Layout,
    redirect: '/joke',
    children: [{
      path: 'joke',
      component: () =>
        import('@/views/joke/index'),
      name: '笑话',
      meta: {
        title: '笑话',
        icon: 'el-icon-lollipop',
        noCache: true
      }
    }]
  },
  {
    path: '/news',
    component: Layout,
    redirect: '/news',
    children: [{
      path: 'news',
      component: () =>
        import('@/views/news/index'),
      name: '每日头条',
      meta: {
        title: '每日头条',
        icon: 'el-icon-document',
        noCache: true
      }
    }]
  },
  {
    path: '/reboot',
    component: Layout,
    redirect: '/reboot',
    children: [{
      path: 'reboot',
      component: () =>
        import('@/views/reboot/index'),
      name: '智能机器人',
      meta: {
        title: '智能机器人',
        icon: 'el-icon-mic'
      }
    }]
  },
  {
    path: '/doing',
    component: Layout,
    redirect: '/doing',
    children: [{
      path: 'doing',
      component: () =>
        import('@/views/doing/index'),
      name: '随机活动',
      meta: {
        title: '随机活动',
        icon: 'el-icon-s-opportunity'
      }
    }]
  },
  {
    path: '/quotations',
    component: Layout,
    redirect: '/quotations',
    children: [{
      path: 'quotations',
      component: () =>
        import('@/views/quotations/index'),
      name: '语录',
      meta: {
        title: '语录',
        icon: 'el-icon-info'
      }
    }]
  },
  {
    path: '/author',
    component: Layout,
    redirect: '/author',
    children: [{
      path: 'author',
      component: () =>
        import('@/views/author/index'),
      name: '诗人信息',
      meta: {
        title: '诗人信息',
        icon: 'el-icon-user-solid'
      }
    }]
  },
  {
    path: '/randomImage',
    component: Layout,
    redirect: '/randomImage',
    children: [{
      path: 'randomImage',
      component: () =>
        import('@/views/randomImage/index'),
      name: '随机图片',
      meta: {
        title: '随机图片',
        icon: 'el-icon-picture'
      }
    }]
  },
  {
    path: '/music',
    component: Layout,
    redirect: '/music',
    children: [{
      path: 'music',
      component: () =>
        import('@/views/music/index'),
      name: '随机音乐',
      meta: {
        title: '随机音乐',
        icon: 'el-icon-video-play'
      }
    }]
  },
  {
    path: '/buyerShow',
    component: Layout,
    redirect: '/buyerShow',
    children: [{
      path: 'buyerShow',
      component: () =>
        import('@/views/buyerShow/index'),
      name: '淘宝买家秀',
      meta: {
        title: '淘宝买家秀',
        icon: 'el-icon-picture-outline-round'
      }
    }]
  },
  {
    path: '/garbage',
    component: Layout,
    redirect: '/garbage',
    children: [{
      path: 'garbage',
      component: () =>
        import('@/views/garbage/index'),
      name: '垃圾分类',
      meta: {
        title: '垃圾分类',
        icon: 'el-icon-delete'
      }
    }]
  }
]
export const asyncRoutes = [
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

const createRouter = () =>
  new Router({
    mode: 'history', // require service support
    scrollBehavior: () => ({
      y: 0
    }),
    routes: constantRoutes
  })

const router = createRouter()
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
